package com.mall4j.cloud.product.controller.app;

import com.mall4j.cloud.common.response.ServerResponseEntity;
import com.mall4j.cloud.product.model.BrowseHistory;
import com.mall4j.cloud.product.model.Spu;
import com.mall4j.cloud.product.model.SpuHistory;
import com.mall4j.cloud.product.service.BrowseHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/history")
public class BrowseHistoryController {
    @Autowired
    private BrowseHistoryService browseHistoryService;

    @PostMapping("/add")
    public void addBrowseHistory(@RequestParam Long userId, @RequestParam Long spuId){
        browseHistoryService.addBrowseHistory(userId,spuId);
    }

    @GetMapping("/list")
    public ServerResponseEntity<List<SpuHistory>> getBrowseHistoryList(@RequestParam(value = "userId") Long userId) {
        browseHistoryService.deleteHistory();
        return ServerResponseEntity.success(browseHistoryService.getBrowseHistoryList(userId));
    }


}
